package com.qmctl.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Calendar;
import java.util.InvalidPropertiesFormatException;
import java.util.Properties;

public class SysTools {
	public static String getTimeStamp(){	
		//java.util.Date now = new java.util.Date();
		Calendar rightNow = Calendar.getInstance();
		StringBuilder  stringbuilder = new StringBuilder();
		stringbuilder.append(rightNow.get(Calendar.YEAR));
		stringbuilder.append(String.format("%02d",rightNow.get(Calendar.MONTH)+1));
		stringbuilder.append(String.format("%02d",rightNow.get(Calendar.DAY_OF_MONTH)));
		stringbuilder.append(String.format("%02d", rightNow.get(Calendar.HOUR_OF_DAY)));
		stringbuilder.append(String.format("%02d", rightNow.get(Calendar.MINUTE)));
		stringbuilder.append(String.format("%02d", rightNow.get(Calendar.SECOND)));
		return new String(stringbuilder.toString());
	};
	public static String getTimeStampManuanl(){	
		//java.util.Date now = new java.util.Date();
		Calendar rightNow = Calendar.getInstance();
		StringBuilder  stringbuilder = new StringBuilder();
		stringbuilder.append(rightNow.get(Calendar.YEAR));
		stringbuilder.append(String.format("%02d",rightNow.get(Calendar.MONTH)+1));
		stringbuilder.append(String.format("%02d ",rightNow.get(Calendar.DAY_OF_MONTH)));
		stringbuilder.append(String.format("%02d:", rightNow.get(Calendar.HOUR_OF_DAY)));
		stringbuilder.append(String.format("%02d:", rightNow.get(Calendar.MINUTE)));
		stringbuilder.append(String.format("%02d", rightNow.get(Calendar.SECOND)));
		return new String(stringbuilder.toString());
	}
	public static String getProperty(String key,Properties prop) throws InvalidPropertiesFormatException, FileNotFoundException, IOException{
		FileInputStream fios =  new FileInputStream("config"+File.separator+"servercfg.xml");
		
		prop.loadFromXML( fios );
		
		String skey = prop.getProperty(key);
		
		if(fios!=null){
		  try{
			fios.close();
		  }catch(IOException e){
			 skey = "";
		  }
		}
		
		return skey;
		
	}

}
